package gui;

import io.Archivo;
import io.Carpeta;
import io.Cliente;
import java.awt.Component;
import javax.swing.ImageIcon;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;

/**
 *
 * @author Mariano Zapata
 */
public class RenderArbol extends DefaultTreeCellRenderer {
    
    private ImageIcon iconoCliente;
    private ImageIcon iconoDocumento;
    private ImageIcon iconoExpediente;
    
    public RenderArbol()
    {
        super();
        iconoCliente= new ImageIcon(getClass().getResource("/gui/icono/cliente.png"));
        iconoDocumento= new ImageIcon(getClass().getResource("/gui/icono/archivo.png"));
        iconoExpediente= new ImageIcon(getClass().getResource("/gui/icono/expediente.png"));
    }
    
    @Override
    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
    boolean leaf, int row, boolean hasFocus)
    {
        super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
        DefaultMutableTreeNode nodo= (DefaultMutableTreeNode) value;
        Object o= nodo.getUserObject();
        if (o instanceof Carpeta)
        {
            if (((Carpeta) o).esExpediente())
                this.setIcon(iconoExpediente);
            else
            {
                if (expanded)
                    this.setIcon(openIcon);
                else
                    this.setIcon(closedIcon);
            }
        }
        if (o instanceof Cliente)
            this.setIcon(iconoCliente);
        if (o instanceof Archivo)
            this.setIcon(iconoDocumento);
        return this;
    }
}
